package com.djsearch.ui;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.djsearch.R;
import com.djsearch.bean.LoginSuccess;
import com.djsearch.controller.JSONResp;
import com.djsearch.data.ImageManager;
import com.djsearch.data.OperateSQLiteDataBase;
import com.djsearch.data.RequestImage;
import com.djsearch.util.AsyncImageLoader;
import com.djsearch.util.AsyncImageLoader.ImageCallback;

/**
 * 编辑个人信息页面
 * @author chenyang2
 *
 */
public class MyInfoActivity extends BaseActivity{

	private Context mContext;
	private TextView huiyuanText,kahaoText,introInfoText;//会员编号，会员卡号，推荐人
	private TextView nowJinBiText,jiangJinBiText,daiJinQuanText;//现金币，奖金币，代金券
	private OperateSQLiteDataBase operateSQLiteDataBase;
	private TextView editInfoText;
	private Button btnBack;
	private ImageView myPhotoImg;
	private AsyncImageLoader asyncImageLoader;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		mContext = this;
		getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(
				WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
		setContentView(R.layout.my_info_layout);
		asyncImageLoader = new AsyncImageLoader("");
		initView();
		initOnClick();
	}
	
	@Override
	void initHandler() {
		// TODO Auto-generated method stub
		
	}

	@Override
	void initView() {
		// TODO Auto-generated method stub
		btnBack = (Button)findViewById(R.id.btnBack);
		myPhotoImg = (ImageView)findViewById(R.id.myPhotoImg);
//		RequestImage.getIntance(null, "").download("headImage.jpg", myPhotoImg);
        asyncImageLoader.loadDrawable(null,myPhotoImg,"headImage.jpg", new ImageCallback() {
			
			@Override
			public void imageLoaded(ProgressBar progressBar,ImageView imageView,Drawable imageDrawable, String imageUrl, String tag) {
				// TODO Auto-generated method stub
				myPhotoImg.setImageBitmap(ImageManager.drawableToBitmap(imageDrawable,150.0f));
			}
		}); 
		huiyuanText = (TextView)findViewById(R.id.huiYuanNumText);
		kahaoText = (TextView)findViewById(R.id.huiYuanKaHaoText);
		introInfoText = (TextView)findViewById(R.id.introInfoText);
		nowJinBiText = (TextView)findViewById(R.id.nowJinBiText);
		jiangJinBiText = (TextView)findViewById(R.id.jiangJinBiText);
		daiJinQuanText = (TextView)findViewById(R.id.daiJinQuanText);
		editInfoText = (TextView)findViewById(R.id.editInfoText);
		
	}

	
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		setMyInfoData();
	}

	@Override
	void initOnClick() {
		// TODO Auto-generated method stub
		btnBack.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startActivity(mContext, null, 1);
			}
		});
		editInfoText.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(mContext,EditMyInfoActivity.class);
				startActivity(intent);
				overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
			}
		});
	}

	/**
	 * 点击返回键
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			startActivity(mContext, SetActivity.class, 1);
		}
		return false;
	}

	@Override
	void getDataToResolve(JSONResp response) {
		// TODO Auto-generated method stub
	}
	/**
	 * 取出个人信息
	 */
	private void setMyInfoData(){
//		if (operateSQLiteDataBase == null) {
//			operateSQLiteDataBase = OperateSQLiteDataBase
//					.getOperateSQLiteDataBase(this);
//		}
//		LoginSuccess logSuccessBean = operateSQLiteDataBase.getMyInfoData("my_info_table",this);
		
		huiyuanText.setText(preferences.getString("userId", ""));
		introInfoText.setText(preferences.getString("tuijianren", ""));
		nowJinBiText.setText(preferences.getString("xianJinMoney", ""));
		jiangJinBiText.setText(preferences.getString("jiangjinQuan", ""));
		daiJinQuanText.setText(preferences.getString("daiJinQuan", ""));
		
	}
	
}
